{extend name="index/index" /}
{block name="main"}
<style>
    th, td {
        text-align: center;
    }
</style>

<script>

    function change(obj, id, status) {
        // id = $(obj).parents().parents().children(":first").html();
        // $.post("{:url('admin/index/change')}",{id:id,status},function(data){
        //     if(data){
        //     }
        // })
        if (status) {
            $.post("{:url('admin/index/change')}", {code: id, n: 0}, function (data) {
                if (data==1) {
                    $(obj).html('禁用');
                    $(obj).attr('class', 'btn btn-xs btn-danger');
                    $(obj).attr('onclick',"change(this,"+id+",0)");
                } else {
                    alert('请求失败');
                }
            })
        } else {
            $.post("{:url('admin/index/change')}", {code: id, n: 1}, function (data) {
                if (data==1) {
                    $(obj).html('激活');
                    $(obj).attr('class', 'btn btn-xs btn-info');
                    $(obj).attr('onclick',"change(this,"+id+",1)");
                } else {
                    alert('请求失败');
                }
            })
        }
    }

    function detail(id) {
        data = $(id).parents().parents().children(":first").html();
        $.post("{:url('admin/index/showDetail')}", {id: data}, function (data) {
            if (data) {
                $('#name').html(data.nickname);
                $('#ID').html(data.id);
                $('#sex').html(data.sex);
                $('#regtime').html(data.regtime);
                $('#status').html(data.status);
                $('#myModalLabel').html(data.nickname + '的详情 : ');

            } else {
                alert('请求失败,请稍后重试');
            }
        })
    }
</script>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-6 float-left">
                        <img src="/static/home/images/logo.png" alt="">
                    </div>
                    <div class="col-md-6">
                        <b style="color: red;">ID</b> : <span id="ID" style="color:orange;"></span><br>
                        <b>name</b> : <span id="name" style="color:orange;"></span><br>
                        <b>sex</b> : <span id="sex" style="color:orange;"></span><br>
                        <b>status</b> : <span id="status" style="color:orange;"></span><br>
                        <b>regtime</b> : <span id="regtime" style="color:orange;"></span><br>
                        <b>photo</b> : <span id="photo" style="color:orange;">暂无</span><br>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<div class="content-page">
    <div class="content">
        <form action="{:url('admin/index/search')}" class="form-inline" style="margin-bottom: 10px" mathod="get">
            <div class="form-group">
                <div class="input-group">
                    <div class="input-group-addon glyphicon glyphicon-search"></div>
                    <input type="text" class="form-control" id="exampleInputAmount" placeholder="请输入用户名搜索" name="data">
                </div>
            </div>
            <button type="submit" class="btn btn-primary btn-sm">搜索</button>
        </form>
        <table class="table table-hover bg-white-1">
            <tr>
                <th>用户Id</th>
                <th>用户名</th>
                <th>状态</th>
                <th>注册时间</th>
                <th>操作</th>
            </tr>
            {volist name="list" key="k" id="v"}
            <tr>
                <td>{$v['id']}</td>
                <td>{$v['nickname']}</td>
                <td>
                    {if condition="$v['status'] eq 1"}
                    <button onclick="change(this,{$v['id']},{$v['status']})"
                            class="btn  btn-info  btn-xs">激活
                    </button>
                    {else/}
                    <button onclick="change(this,{$v['id']},{$v['status']})" class="btn  btn-danger  btn-xs">
                        禁用
                    </button>
                    {/if}
                </td>
                <td>{:date('Y/m/d H:i:s',$v['regtime'])}</td>
                <td>
                    <button onclick="detail(this)" class="btn btn-xs btn-info" data-toggle="modal"
                            data-target="#myModal">查看详情
                    </button>
                </td>
            </tr>
            {/volist}
        </table>
        {$list->render()}
    </div>
</div>
{/block}
